package insert

import (
	"context"

	"server_1.0/api/internal/svc"
	"server_1.0/api/internal/types"
	"server_1.0/service/question/question"
	"server_1.0/util"

	"github.com/zeromicro/go-zero/core/logx"
)

type InsertQuestionLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewInsertQuestionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InsertQuestionLogic {
	return &InsertQuestionLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *InsertQuestionLogic) InsertQuestion(req *types.QesInsertReq) (resp *types.PostReps, err error) {
	code := util.Success
	Msg := "增添成功"

	ins, _ := l.svcCtx.QuestionRpc.Insert(l.ctx, &question.InsertReq{
		No:   req.No,
		Info: req.Info,
		OPa:  req.OPa,
		OPb:  req.OPb,
		AWa:  req.AWa,
		AWb:  req.AWb,
	})
	if ins.Count == 0 {
		code = util.AddError
		Msg = "增添失败"
	}

	return &types.PostReps{
		Code: code,
		Msg:  Msg,
		Data: map[string]interface{}{
			"res": ins.QRs,
		},
	}, nil
}
